var Recycle = {
	del:function(ids){
		if(ids == null){
			return;
		}
		confirm('确定要删除选中的记录？', function(){
			$.ajax({
				type: "POST",
				url: "remove",
			    data: {
					ids:ids
				},
			    success: function(r){
					if(r.success){
						alert('操作成功', function(index){
							$("#jqGrid").trigger("reloadGrid");
						});
					}else{
						alert(r.msg);
					}
				}
			});
		});
	},
	refresh:function(){
		$("#jqGrid").trigger("reloadGrid");
	}
};
$(function () {
    $("#jqGrid").jqGrid({
        url: 'page-list',
        datatype: "json",
        colModel: [			
			{ label: 'ID', name: 'id', index: 'id', width: 20, key: true },
			{ label: '短链接', name: 'shortUrl', index: 'shortUrl', width: 60 }, 	
			{ label: '原始链接', name: 'url', index: 'url', width: 300 }, 		
			{ label: '删除时间', name: 'deleteTime', index: 'deleteTime', width: 60 }, 	
			{ label: '最后使用时间', name: 'lastUsedTime', index: 'lastUsedTime', width: 60 }, 			
			{ label: '创建时间', name: 'createTime', index: 'createTime', width: 60 }, 			
			{ label: '失效时间', name: 'expireTime', index: 'expireTime', width: 60 }			
        ],
		viewrecords: true,
        height: 600,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "list",
            page: "currPage",
            total: "totalPage",
            records: "totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        styleUI : "Bootstrap",
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        },
        beforeSelectRow: function(rowId, e) { 
        	if($(e.target).is("input[type='checkbox']") && $(e.target).prop("checked")){
        		$(e.target).parent().parent().addClass("success");
        		$("#jqGrid").getGridParam("selarrrow").push(rowId);
        		return true; 
        	}else if($(e.target).is("input[type='checkbox']") && !$(e.target).prop("checked")){
        		$(e.target).parent().parent().removeClass("success");
        		removeByValue($("#jqGrid").getGridParam("selarrrow"),rowId);
        		return true; 
        	}
        	return true; 
        },
    });
});
